// pages/oneself/profile/profile.js
const app = getApp()
const connector = require('../../../utils/connector.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bar_Height: wx.getSystemInfoSync().statusBarHeight + 45,
    name: "暂未填写",//姓名
    sex: "暂未填写",//性别
    phone: "暂未填写",//手机
    address: "暂未填写",//地址
    company: "暂未填写",//驾校
    types: "暂未填写",//车型
    user:{
      idcard: "暂未填写",
      mail_address: "暂未填写",
      phone: "暂未填写",
      realname: "暂未填写",
      school_id: "暂未填写",
    },

    identity: app.globalData.identity,//身份：false：学员（默认）true：教练

  },
  //测试：身份转换
  identity(e) {
    this.setData({
      identity: !app.globalData.identity
    })
    app.globalData.identity = !app.globalData.identity

  },
  //编辑
  redact(e) {
    wx.navigateTo({
      url: './coachEdit',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    // queryWebUser(that)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // userCoachGet(this)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideShareMenu()
    userCoachGet(this)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
/**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {
    var that = this
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新

  },
})
//获取用户信息
function userCoachGet(that){
  if(wx.getStorageSync("users") && wx.getStorageSync("users").picture){
    let obj = wx.getStorageSync("users")
    if(obj.sex == 1){
      obj.sexs = "男"
    }else{
      obj.sexs = "女"
    }
    that.setData({
      user:obj
    })
  }else{
    connector.getFunc(connector.connector().userCoachGet, "", "get", app.tokens, function (res) {
      console.log(res.data)
      if(res.statusCode == 200){
          console.log(res.data.result)
          wx.setStorageSync("users",res.data.result)
          let obj = res.data.result
          if(obj.sex == 1){
            obj.sexs = "男"
          }else{
            obj.sexs = "女"
          }
          that.setData({
            user:obj
          })
      }
      
    }, function (res) {
      wx.showToast({
        title: "内部错误",
        icon: 'none',
        duration: 1000
      })
    })
  }
  
}